package com.sky.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sky.entity.Setmeal;
import com.sky.mapper.SetmealMapper;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealOverViewVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class SetmealServiceImpl
        extends ServiceImpl<SetmealMapper, Setmeal>
        implements SetmealService {

    @Autowired
    private SetmealMapper setmealMapper;

    /**
     * 根据套餐状态获取统计信息
     *
     * 此方法用于获取售出和停售的套餐数量，以便在overview页面展示
     * 它通过调用setmealMapper的getSold和getDiscontinued方法来获取数据
     *
     * @return SetmealOverViewVO 包含售出和停售套餐数量的视图对象
     */
    public SetmealOverViewVO getCountByStatus() {
        // 获取售出的套餐数量
        Integer sold = setmealMapper.getSold();
        // 获取停售的套餐数量
        Integer discontinued = setmealMapper.getDiscontinued();
        // 构建并返回包含套餐数量信息的视图对象
        return SetmealOverViewVO.builder()
                .sold(sold)
                .discontinued(discontinued)
                .build();
    }

}
